#!/usr/bin/env python
# -*- coding: utf-8 -*-
###########################################################################
#   Copyright (C) 2008 by Serj Poltavsky                                  #
#   serge.uliss at gmail.com                                              #
#                                                                         #
#   This program is free software; you can redistribute it and/or modify  #
#   it under the terms of the GNU General Public License as published by  #
#   the Free Software Foundation; either version 3 of the License, or     #
#   (at your option) any later version.                                   #
#                                                                         #
#   This program is distributed in the hope that it will be useful,       #
#   but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#   GNU General Public License for more details.                          #
#                                                                         #
#   You should have received a copy of the GNU General Public License     #
#   along with this program. If not, see <http://www.gnu.org/licenses/>   #
###########################################################################

import os
import unittest
from dvdformat import DvdFormat

class TestVideoFormat(unittest.TestCase):
    def setUp(self):
        self.dvdformat = DvdFormat.pal()

    def test_init(self):
        self.assertEqual(self.dvdformat.format, 'pal')
        self.assertEqual(self.dvdformat.fps, 25)
        self.assertEqual(self.dvdformat.samplerate, 48000)
        self.assertEqual(self.dvdformat.aspect, (4, 3))
        self.assertEqual(self.dvdformat.size, (720, 576))

    def test_static(self):
        self.assert_(DvdFormat.valid_format('pal'))
        self.assert_(DvdFormat.valid_format('ntsc'))
        self.assert_(not DvdFormat.valid_format('foo'))

        self.assert_(DvdFormat.valid_aspect((4, 3)))
        self.assert_(DvdFormat.valid_aspect((16, 9)))
        self.assert_(not DvdFormat.valid_aspect((1, 2)))

        self.assert_(DvdFormat.valid_samplerate(48000))
        self.assert_(not DvdFormat.valid_samplerate(48001))

        self.assert_(DvdFormat.valid_codec('pal', 'mp2'))
        self.assert_(DvdFormat.valid_codec('pal', 'ac3'))
        self.assert_(DvdFormat.valid_codec('pal', 'pcm'))
        self.assert_(not DvdFormat.valid_codec('pal', 'foo'))

        self.assert_(not DvdFormat.valid_codec('ntsc', 'mp2'))
        self.assert_(DvdFormat.valid_codec('ntsc', 'ac3'))
        self.assert_(DvdFormat.valid_codec('ntsc', 'pcm'))

        self.assert_(DvdFormat.valid_size('pal', (720, 576)))
        self.assert_(not DvdFormat.valid_size('pal', (720, 480)))
        self.assert_(DvdFormat.valid_size('ntsc', (720, 480)))

    def test_prop(self):
        self.assertRaises(ValueError, self.dvdformat.set_format, 'foo')
        self.assertRaises(ValueError, self.dvdformat.set_size, (720,480))
        self.assertRaises(ValueError, self.dvdformat.set_aspect, (1,1))
        self.dvdformat.size = (704, 576)
        self.assertRaises(ValueError, self.dvdformat.set_aspect, (16,9))

